﻿Imports Entidades
Imports System.Data
Imports System.Data.Odbc
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class DBRepartidores
    Public cn As OdbcConnection
    Public con As SqlConnection
    Sub New()

        Try
            cn = New OdbcConnection("UID=pruebasexto" & _
         ";PWD=pruebasexto123" & _
         ";DATABASE=pruebasexto" & _
         ";SERVER=db4free.net" & _
         ";DRIVER={MySQL ODBC 3.51 Driver};")
            cn.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
            MsgBox("Error al conectarse")
        End Try


    End Sub
    Function AltaRepartidor(ByVal nodo As Repartidores) As Boolean
        Try
            Try
                Dim cmd As OdbcCommand = New OdbcCommand("{call Alta_repartidor (?,?,?,?)}", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@nc", nodo.R)
                cmd.Parameters.AddWithValue("@ci", nodo.R1)
                cmd.Parameters.AddWithValue("@fn", nodo.R2)
                cmd.Parameters.AddWithValue("@dir", nodo.R3)



                cn.Open()
                cmd.ExecuteNonQuery()

            Catch o As OdbcException
                MsgBox(o.Message.ToString)
                Return False
            Finally
                cn.Close()
            End Try
            Return True

        Catch ex As Exception


        End Try
        Return False

    End Function
    Function BajaRepartidor(ByVal nodo As Repartidores) As Boolean
        Try
            Try
                Dim cmd As OdbcCommand = New OdbcCommand("{call baja_repartidor (?)}", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@id", nodo.R4)

                cn.Open()
                cmd.ExecuteNonQuery()

            Catch o As OdbcException
                MsgBox(o.Message.ToString)
                Return False
            Finally
                cn.Close()
            End Try
            Return True

        Catch ex As Exception


        End Try
        Return False

    End Function
    
    Function consultarepartidor() As ArrayList


        Dim arr As ArrayList = New ArrayList
        Dim cmd As OdbcCommand = New OdbcCommand("{call Consulta_repartidor ()}", cn)
        Dim dr As OdbcDataReader = cmd.ExecuteReader()
        While dr.Read
            Dim nodo As Repartidores = New Repartidores

            nodo.R = dr.GetString(0)
            arr.Add(nodo) 

        End While
        dr.Close()

        Return arr


    End Function
End Class
